package com.example.demo.test.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.nio.charset.Charset;

public class SelectorClientTest3 {
    public static void main(String[] args) throws IOException {
        SocketChannel sc=SocketChannel.open();
        sc.connect(new InetSocketAddress("localhost",8082));
        System.out.println("连接服务端");
        int count=0;
        while (true){
            ByteBuffer byteBuffer=ByteBuffer.allocate(1024*1024);
            count += sc.read(byteBuffer);
            System.out.println(count);
            byteBuffer.clear();
            if(count==300000){
                break;
            }
        }
        sc.write(Charset.defaultCharset().encode("hello word!"));
    }
}
